<?php


namespace app\admin\controller;


use http\Params;
use think\facade\Db;

class Uniapp
{
    private $data = [];

    public function getCarousel()
    {
        $result = Db::name('video')
            ->field('id,cover as image')
            ->where('id','>=','SELECT FLOOR( MAX(id) * RAND()) FROM `video` ')
            ->limit(5)
            ->order(['id'=>'DESC'])
            ->select();
        $this->data=$result;
        return $this->responseData();
    }

    public function getHotYugao()
    {
        $offset = mt_rand(0,10000);
        $result = Db::name('video')
            ->field('id,cover as movie_cover,title as movie_name,video as movie_url,10 as movie_score,cover as movie_back_image')
            ->limit($offset,7)
            ->order(['id'=>'DESC'])
            ->select();
        $this->data=$result;
        return $this->responseData();
    }

    public function getGuess()
    {
        $offset = mt_rand(0,10000);
        $fields = [
            'id',
            'cover as movie_cover',
            'title as movie_name',
            'video as movie_url',
            '8 as movie_score',
            'type as movie_msg',
            '"未知" as movie_person',
            'create_time as date'
        ];
        $result = Db::name('video')
            ->field(implode(',',$fields))
            ->limit($offset,7)
            ->order(['id'=>'DESC'])
            ->select()->toArray();
        foreach ($result as $k=>$item) {
            $item[$k]['date'] = date('Y-m-d',$item['date']);
        }
        $this->data=$result;
        /*$this->data = [
            [
                'id'           => 1,
                'movie_cover'  => 'http://localhost/oa_admin/public/static/image/20.jpg',
                'movie_name'   => '我的机器人女友',
                'movie_url'    => '',
                'movie_score'  => 5.6,
                'movie_msg'    => '2018 美国 / 科幻 / 战争 / 悬疑',
                'movie_person' => '林允儿 /  Angelababy / 吴佩慈',
                'date'         => '2020-08-06',
            ],
            [
                'id'           => 1,
                'movie_cover'  => 'http://localhost/oa_admin/public/static/image/21.jpg',
                'movie_name'   => '我的机器人女友',
                'movie_url'    => '',
                'movie_score'  => 5.8,
                'movie_msg'    => '2018 美国 / 科幻 / 战争 / 悬疑',
                'movie_person' => '林允儿 /  Angelababy / 吴佩慈',
                'date'         => '2020-08-06',
            ],
            [
                'id'           => 1,
                'movie_cover'  => 'http://localhost/oa_admin/public/static/image/22.jpg',
                'movie_name'   => '我的机器人女友',
                'movie_url'    => '',
                'movie_score'  => 5,
                'movie_msg'    => '2018 美国 / 科幻 / 战争 / 悬疑',
                'movie_person' => '林允儿 /  Angelababy / 吴佩慈',
                'date'         => '2020-08-06',
            ],
            [
                'id'           => 1,
                'movie_cover'  => 'http://localhost/oa_admin/public/static/image/23.jpg',
                'movie_name'   => '我的机器人女友',
                'movie_url'    => '',
                'movie_score'  => 6,
                'movie_msg'    => '2018 美国 / 科幻 / 战争 / 悬疑',
                'movie_person' => '林允儿 /  Angelababy / 吴佩慈',
                'date'         => '2020-08-06',
            ],
            [
                'id'           => 1,
                'movie_cover'  => 'http://localhost/oa_admin/public/static/image/24.jpg',
                'movie_name'   => '我的机器人女友',
                'movie_url'    => '',
                'movie_score'  => 4,
                'movie_msg'    => '2018 美国 / 科幻 / 战争 / 悬疑',
                'movie_person' => '林允儿 /  Angelababy / 吴佩慈',
                'date'         => '2020-08-06',
            ],
        ];
        shuffle($this->data);*/
        return $this->responseData();
    }

    public function responseData()
    {
        return json([
            'status'  => 200,
            'message' => '请求成功！',
            'data'    => $this->data
        ]);
    }
}